package cn.otrue.patienthealthmanager.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import cn.otrue.patienthealthmanager.R;
import cn.otrue.patienthealthmanager.bean.ThreadModel;
import cn.otrue.patienthealthmanager.utils.DensityUtil;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

public class CommunityFragtAdpater extends BaseAdapter {

	
	
	public void ImageSet(String imgurl, ImageView img_headPhoto) {

		DisplayImageOptions options = new DisplayImageOptions.Builder()
				.showImageOnLoading(R.drawable.iv_user_photo)
				.showImageOnFail(R.drawable.iv_user_photo)
				.showImageForEmptyUri(R.drawable.iv_user_photo)
				.cacheInMemory(true)
				.cacheOnDisk(true)
				.bitmapConfig(Bitmap.Config.RGB_565)
				.displayer(
						new RoundedBitmapDisplayer(DensityUtil.dip2px(context,
								40))).build();
		ImageLoader.getInstance().displayImage(imgurl, img_headPhoto, options);
	}



	
	
	
		
	private List<ThreadModel> goods;
	private LayoutInflater inflater;
	private Context context;
	private DisplayImageOptions options;
	
	


	public CommunityFragtAdpater(Context context,
			List<ThreadModel> goods) {
		super();
		this.goods = goods;
		this.context = context;
		inflater= LayoutInflater.from(this.context);
		
	
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return goods.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		arg1 = inflater.inflate(R.layout.community_partition_item, null);
		ImageView	pe_head_image = (ImageView) arg1.findViewById(R.id.pe_head_image);
		TextView tv_community_title = (TextView) arg1
				
				.findViewById(R.id.tv_community_title);
		TextView tv_zan = (TextView) arg1
				
				.findViewById(R.id.tv_zan);
		
		TextView tv_community_name = (TextView) arg1
				.findViewById(R.id.tv_community_name);
		TextView tv_community_time = (TextView) arg1
				.findViewById(R.id.tv_community_time);
		TextView tv_community_num = (TextView) arg1
				.findViewById(R.id.tv_community_num);
		ThreadModel eachMap = goods.get(arg0);
		String url = eachMap.getHeadimg();
	
		ImageSet(url,pe_head_image);
		tv_zan.setText("("+eachMap.getPraiseCount()+")"+"");
		tv_community_title.setText(eachMap.getThreadTitle() + "");
		tv_community_name.setText(eachMap.getNickName() + "");
		tv_community_time.setText(eachMap.getCreatetime().substring(0, 10) + "");
		tv_community_num.setText("("+eachMap.getReplyCount()+")" + "");
		return arg1;
	}

}
